package com.topscomm.mpm.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * com.topscomm.mpm.utils
 * MengM_
 * 2021/8/11 11:09
 * mpm
 */
public class ConvertTimeUtil {
    private final static String[] format1 = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
    private final static String[] format2 = {"零","一","二","三","四","五","六","七","八","九"};
    private final static String[] format3 = {"〇","一","二","三","四","五","六","七","八","九"};

    public static String dataToUpper1(String dateString) {
        return dataToUpper(dateString, format1);
    }
    public static String dataToUpper2(String dateString) {
        return dataToUpper(dateString, format2);
    }
    public static String dataToUpper3(String dateString) {
        return dataToUpper(dateString, format3);
    }
    /**
    * @Description:     日期转化为大小写
    * @Author:         mengmeng
    * @Date:           2021/8/11 11:11
    * @Version:        1.0
    */
    public static String dataToUpper(String dateString, String[] format) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date dateTime = null;
        try {
            dateTime = simpleDateFormat.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar ca = Calendar.getInstance();
        ca.setTime(dateTime);
        int year = ca.get(Calendar.YEAR);
        int month = ca.get(Calendar.MONTH) + 1;
        int day = ca.get(Calendar.DAY_OF_MONTH);
        return numToUpper(year, format) + "年" + monthToUppder(month, format) + "月" + dayToUppder(day, format) + "日";
    }

    /**
    * @Description:    将数字转化为大写（字体格式可自己定义）
    * @Date:           2021/8/11 11:11
    * @Version:        1.0
    */
    public static String numToUpper(int num, String[] format) {
        char[] str = String.valueOf(num).toCharArray();
        String rstr = "";
        for (int i = 0; i < str.length; i++) {
            rstr = rstr + format[Integer.parseInt(str[i] + "")];
        }
        return rstr;
    }

    /**
    * @Description:    月转化为大写
    * @Author:         mengmeng
    * @Date:           2021/8/11 11:11
    * @Version:        1.0
    */
    public static String monthToUppder(int month, String[] format) {
        if(month < 10) {
            return numToUpper(month, format);
        } else if(month == 10){
            return "十";
        } else {
            return "十" + numToUpper(month - 10, format);
        }
    }

    /**
    * @Description:    日转化为大写
    * @Author:         mengmeng
    * @Date:           2021/8/11 11:10
    * @Version:        1.0
    */
    public static String dayToUppder(int day, String[] format) {
        if(day < 20) {
            return monthToUppder(day, format);
        } else {
            char[] str = String.valueOf(day).toCharArray();
            if(str[1] == '0') {
                return numToUpper(Integer.parseInt(str[0] + ""), format) + "十";
            }else {
                return numToUpper(Integer.parseInt(str[0] + ""), format) + "十" + numToUpper(Integer.parseInt(str[1] + ""), format);
            }
        }
    }
    /**
     * @author: houyuhang
     * @date: 2022/12/14
     * @description: 将时间转换为本周的周一
     * @modify:
     */
    public static Calendar convertToThisWeekMonday(Calendar calendar) {
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            calendar.add(Calendar.DATE, -1);
        }
        calendar.set(Calendar.DAY_OF_WEEK, calendar.MONDAY);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        return calendar;
    }
    /**
     * @author: houyuhang
     * @date: 2022/12/14
     * @description: 将时间转换为本周的周日
     * @modify:
     */
    public static Calendar convertToThisWeekSunday(Calendar calendar) {
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            calendar.add(Calendar.DATE, -1);
        }
        calendar.set(Calendar.DAY_OF_WEEK, calendar.MONDAY);
        calendar.add(Calendar.DATE, 6);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        return calendar;
    }
    /**
     * @author: houyuhang
     * @date: 2023/06/05
     * @description: 将时间转换为明天
     * @modify:
     */
    public static Calendar convertToTomorrow(Calendar calendar) {
        calendar.add(Calendar.DATE, 1);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        return calendar;
    }
}
